import request from "@/utils/request";

const BASE_URL = "/api/v1/management/";

const ProductManagementAPI = {
  /**
   * 获取字典分页列表
   *
   * @param queryParams 查询参数
   * @returns 字典分页结果
   */
  getPage(queryParams: ProductManagementPageQuery) {
    return request<any, PageResult<ProductManagementPageVO[]>>({
      url: `${BASE_URL}`,
      method: "get",
      params: queryParams,
    });
  },

  /**
   * 获取字典数据表单
   *
   * @param id 字典ID
   * @returns 字典数据表单
   */
  getFormData(id: number) {
    return request<any, ResponseData<ProductManagementForm>>({
      url: `${BASE_URL}${id}/`,
      method: "get",
    });
  },

  /**
   * 新增字典数据
   *
   * @param data 字典数据
   */
  add(data: ProductManagementForm) {
    return request({
      url: `${BASE_URL}`,
      method: "post",
      data: data,
    });
  },

  /**
   * 修改字典数据
   *
   * @param id 字典ID
   * @param data 字典数据
   */
  update(id: number, data: ProductManagementForm) {
    return request({
      url: `${BASE_URL}${id}/`,
      method: "patch",
      data: data,
    });
  },

  /**
   * 删除字典
   *
   * @param ids 字典ID，多个以英文逗号(,)分隔
   */
  deleteByIds(ids: string) {
    return request({
      url: `${BASE_URL}${ids}/`,
      method: "delete",
    });
  },

  deleteById(id: number) {
    return request({
      url: `${BASE_URL}${id}/`,
      method: "delete",
    });
  },

  /**
   * 获取字典的数据项
   *
   * @param dictCode 字典编码
   * @returns 字典数据项
   */
  getOptions(product: string) {
    return request<any, MaterialOptionType[]>({
      url: `${BASE_URL}${product}/`,
      method: "get",
    });
  },
};

export default ProductManagementAPI;

/**
 * 字典查询参数
 */
export interface ProductManagementPageQuery extends PageQuery {
  /** 关键字(字典数据值/标签) */
  search?: string;
  product?: string;
}

export interface MaterialOptionType extends OptionType {
  unit_name?: string;
}

/**
 * 字典分页对象
 */
export interface ProductManagementPageVO {
  /**
   * 字典ID
   */
  id?: number;
  product?: string;
  line?: string;
  uph?: number;
  unit_name?: string;
  staff?: number;
  status: number;
  create_time?: Date;
  update_time?: Date;
  create_user?: string;
  update_user?: string;
}

/**
 * 字典
 */
export interface ProductManagementForm {
  /**
   * 字典ID
   */
  id?: number;
  product?: string;
  line?: string;
  uph?: number;
  unit_name?: string;
  staff?: number;
  status?: number;
  is_update?: boolean;
}
